package org.ling.xuan.dialog;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.components.JBTabbedPane;
import org.jetbrains.annotations.Nullable;
import org.ling.xuan.entity.mo.Setting;
import org.ling.xuan.pannel.CommonSettingPanel;
import org.ling.xuan.pannel.EmailSettingPanel;
import org.ling.xuan.pannel.ProjectSettingPanel;

import javax.swing.*;


public class SettingDialog extends DialogWrapper {
    private final JBTabbedPane tabbedPane;
    private Setting settingVo;
    private final EmailSettingPanel emailPanel;
    private final CommonSettingPanel commonPanel;
    private final ProjectSettingPanel projectPanel;

    public SettingDialog(@Nullable Project project, boolean canBeParent, Setting settingVo) {
        super(project, canBeParent);
        this.settingVo = settingVo;
        if (this.settingVo == null) {
            this.settingVo = new Setting();
        }
        setTitle("Setting Configuration");
        tabbedPane = new JBTabbedPane();
        tabbedPane.addTab("Common Setting", commonPanel = new CommonSettingPanel(settingVo.getCommonSetting()));
        tabbedPane.addTab("Email Setting", emailPanel = new EmailSettingPanel(settingVo.getEmailSetting()));
        tabbedPane.addTab("Project Setting", projectPanel = new ProjectSettingPanel(project, settingVo.getProjectSetting()));
        init();
    }

    @Override
    protected @Nullable JComponent createCenterPanel() {
        return tabbedPane;
    }

    public Setting getSetting() {
        settingVo.setEmailSetting(emailPanel.getSetting());
        settingVo.setCommonSetting(commonPanel.getCommonSetting());
        settingVo.setProjectSetting(projectPanel.getSetting());
        return settingVo;
    }
}
